/**
 * XQuery to Scala Translator
 * Fatemeh Borran-Dejnabadi
 * 9 November 2004
 */

package xquery2src;

/** This class provides methods for encoding a location in
 *  a source file (line/column) into a single integer.
 */
object Position {

    /** number of bits reserved for the column.
     */
    val columnBits:int = 12;

    val columnMask:int = (1 << columnBits) - 1;

    /** undefined position
     */
    val UNDEFINED:int = 0;

    /** first position in a source file
     */
    val FIRST:int = (1 << columnBits) | 1;

    /** encode a line and column number into a single int
     */
    def encode(line:int, col:int):int = {
      return (line << columnBits) | (col & columnMask);
    }

    /** get the line number out of an encoded position
     */
    def line(pos:int):int = {
      return pos >>> columnBits;
    }

    /** return the column number of an encoded position
     */
    def column(pos:int):int = {
      return pos & columnMask;
    }
}
